# coding:utf-8
from ultralytics import YOLO
import cv2

# 所需加载的模型目录
path = 'D:/PycharmProjects/yolo_v8/detection/runs/detect/train3/weights/best.pt'
# 需要检测的图片地址
img_path = "D:/PycharmProjects/yolo_v8/images/val/209.jpg"

model = YOLO(path, task='detect')

# 检测图片
results = model(img_path)
res = results[0].plot()
boxes = results[0].boxes.cpu().numpy()
xyxys = boxes.xyxy
for xyxy in xyxys:
    cv2.rectangle(res, (int(xyxy[0]), int(xyxy[1])), (int(xyxy[2]), int(xyxy[3])),(0,255,0))
print(xyxys)
cv2.imshow('11',res)
# cv2.imshow("YOLOv8 Detection", res)
cv2.waitKey(0)
